import Vue from 'vue';
import App from './App.vue';
import store from './store';
import router from './router';
import iView from 'view-design';


// Vue.config.productionTip = false;
Vue.use(iView)

//////首页响应式布局rem开始//////
const setHtmlFontSize = () => {
    const htmlDom = document.getElementsByTagName('html')[0];
    let htmlWidth = document.documentElement.clientWidth || document.body.clientWidth;
    if (htmlWidth >= 750) {
      htmlWidth = 750;
    }
    if (htmlWidth <= 320) {
      htmlWidth = 320;
    }
    htmlDom.style.fontSize = `${htmlWidth / 7.5}px`;
  };
  window.onresize = setHtmlFontSize;
  setHtmlFontSize();
//////页响应式布局rem开始/////////

router.beforeEach((to, from, next) => {
    // console.log(to)
    // console.log(localStorage.getItem("token"))
    var a = localStorage.getItem("token");
    console.log(a)
    
    var b = to.name;
    if(b=="login"){
        next()
    }else{
        if(a){
            next();
        }else{
            next({'path':'/login'})
        }
    }
})
Vue.directive('tap', (el, binding) => {
    el.addEventListener('touchstart', () => {
        router.push({
            name: binding.value
        });
    }, false);
});

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app');